import csv
from datetime import datetime
import pygal


filename = 'D:\\Users\\kai\\PycharmProjects\\python_mat\\Fiberhome_DataAnalysis\\co2.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    dates,highs,winds = [],[],[]
    for row in reader:
        try:
            current_date = datetime.strptime(row[1]+'-'+row[2]+'-'+row[3]+'-'+row[4],"%Y-%m-%d-%H")
            if int(row[5])>=0:
                high = int(row[5])
                print(high)
            wind = row[10]
        except ValueError:
            print(current_date,'missing data')
        else:
            dates.append(current_date)
            highs.append(high)
            winds.append(wind)


chart = pygal.Bar(x_label_rotation=45)
chart._title='Daily high PM2.5'
chart.x_labels = dates
chart.add('',highs)
chart.render_to_file('PM.svg')
